var authorization = myStorage.getItem('memberidToken');
console.log(authorization);

var addressMsg = GetQueryString('addressMsg');
var addrMsg = JSON.parse(addressMsg);

var isDefault = 1;
var name='';
var mobile = '';
var province = '';
var city = '';
var region = '';
var town='';
var detail = '';

$('#name').val(addrMsg.name);
$('#mobile').val(addrMsg.mobile);
$('#detail').val(addrMsg.detail);
$('#cityResult').text(addrMsg.province+' '+addrMsg.city+' '+addrMsg.region+' '+addrMsg.town+' '+addrMsg.detail);
province = addrMsg.province;
city = addrMsg.city;
region = addrMsg.region;
town = addrMsg.town;
detail = addrMsg.detail;
var isDefault = addrMsg.isDefault;
console.log(isDefault);

if(!isDefault){
	$('#default').find('img').attr('src','../images/switchBtn.png');
}else{
	$('#default').find('img').attr('src','../images/switchBtn2.png');
}
$('#default').on('click',function(){
	if(!isDefault){		//设为默认
		$(this).find('img').attr('src','../images/switchBtn2.png');
		isDefault = 1;
	}else{				//取消默认
		$(this).find('img').attr('src','../images/switchBtn.png');
		isDefault = 0;
	}
});


//级联示例
var cityPicker = new mui.PopPicker({
	layer: 3
});
cityPicker.setData(cityData3);
var showCityPickerButton = document.getElementById('showCityPicker');
var cityResult = document.getElementById('cityResult');
showCityPickerButton.addEventListener('tap', function(event) {
	cityPicker.show(function(items) {
		cityResult.innerText = items[0].text + " " + items[1].text + " " + items[2].text;
		province = items[0].text;	//省份
		city = items[1].text;		//城市
		region = items[2].text;		//区域
		//返回 false 可以阻止选择框的关闭
		//return false;
	});
}, false);


$('#submit').on('click',function(){
	name = $('#name').val();
	mobile = $('#mobile').val();
	detail = $('#detail').val();
	if(name==''){
		mui.toast('请填写名字');
		return false;
	}
	if(mobile==''||!checkMobile(mobile)){
		mui.toast('请输入手机号');
		return false;
	}
	if(detail==''){
		mui.toast('请填写详细地址');
		return false;
	}
	var addressParam = {
		addressId:addrMsg.id,
		name:name,
		mobile:mobile,
		province:province,
		city:city,
		region:region,
		town:town,
		detail:detail,
		isDefault:isDefault,		//是否默认
	}
	ltNetwork.tokenPost(configUrl.ADDRESSMODIFY_URL,addressParam,authorization,function(res){
		console.log(res);
		if(res.status==200){
			mui.toast('修改成功');
			window.location.href=document.referrer;
		}else{
			mui.toast('请重新尝试');
		}
		
	},function(msg){
		console.log(msg);
	});
});
